Lua templating/InfoboxBuilder
What's new? We are happy to introduce a completely new Infobox Builder! It makes creating templates for Infoboxes much easier and faster. You will also benefit from faster rendering of pages. What do I need? Copy these modules: * Module:InfoboxBuilder * Module:InfoboxBuilderView * Module:HF Simply create pages with matching names on your wikia and copy the content. Step 1 - Provide data If you convert an old wikitext template to Lua you probably have some articles that provide you the data. So, good news! You don't have to change anything! Just update your template and the rest will happen. However, if you write a new template you need some input. In this example we will use this wikitext code: It calls a Template:LuaInfobox article and passes some info about the InfoboxBuilder module. Step 2 - Infobox Template We are ready to go! At first, we will create a template to model our infobox. To be consistent with the data from Step 1 let's call it Template:LuaInfobox. Invoking InfoboxBuilder module We will get to actual building in a second. Let's start with a necessary structure there: The new thing here is the "#invoke" command which is used to call Lua modules in wikitext templates. The syntax Let's build the infobox you can see in this article using the new syntax that InfoboxBuilder uses: } | 2:Type = MainImage | 2:Label = Module or Lua logo | 2:Value = } | 3:Type = Header | 3:Label = Basic info | 3:Value = Basic Information | 4:Type = Line | 4:Label = Module's name | 4:Value = } | 5:Type = Line | 5:Label = Dependencies | 5:Value = } | 6:Type = Line | 6:Label = Version | 6:Value = } }} The general pattern for each argument is: | Index:Key = Value Variables Arguments with a 0 index are general variables. The always present ones are: Theme = "default", -- Adds prefix to CSS classes CustomModule = " ", -- Defines a path to a module with custom functions MainImageCaption = "Off", -- Toggles display of Label in the Main Image field ToggleContentLongerThan = 1000 -- Makes fields with long values collapsible You can also define your own variables, e.g. if you want to use a magic word add: | 0:Pagename = The pagename of an article using this template will be passed now for a later use. Fields Fields are blocks of which an infobox is made. Its basic definition consists of Type, Label and Value. Types that are available for now are: * Title * Header * Line * Image * MainImage * Link * Footer Each element has its own CSS class so you can style them differently. They also have different HTML markup. Type, Label and Value are assigned to one field by having the same numeric index. Label is displayed by default for Line and Image and you can turn in on for MainImage. For other fields it is has an informative and descriptive role. The default behavior for Line type blocks is that it is not displayed if its Value is empty. That's why it is important to use a | (pipe) to pass an empty string if no value is provided in an article. But this is quite boring. Let's make our infobox a little bit more fancy! Step 3 - Custom modules If you want to process a Label or a Value of a field you can include your own Lua module by passing its full name (with a Module: prefix) in a CustomModule variable e.g.: } | 5:ValueMethod = Dependencies There is no naming convention to stick to, however using a module's name for a main variable and fields' names for functions will help you keep things organised. You can also process Labels in the same way. Just add LabelMethod argument with a name of a function you want to use. Multiple values Since every method has access to all arguments grouped in one field you can pass multiple values to it. For example - we want to point that all dependencies are required. We can do it by adding a new argument to the Dependencies field: | 5:Type = Line | 5:Label = Dependencies | 5:Value = } | 5:ValueDesc = } | 5:ValueMethod = Dependencies and define its value in an article: | Dependencies = InfoboxBuilderView; HF | DependenciesDesc = (all are required) Now we can use it to add additional notes to the Dependencies field: function LuaInfobox.Dependencies( field, vars ) local output = "" local dependencies = HF.explode( ";", field.Value ) for i, dependency in ipairs( dependencies ) do output = output .. "" .. dependency .. "" .. "; " end if string.sub( output, -2, -1 ) "; " then output = string.sub( output, 1, -3 ) -- Remove last semi-colon and space end if not HF.isempty( field.ValueDesc ) then output = output .. " " .. field.ValueDesc end return output end Step 4 - Get creative! Building infoboxes using custom Lua modules gives you a lot more possibilities than wikitext templates alone. Check out the articles available in Category:Lua and... get creative! Infobox Builder